﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using BLL;

namespace Web.admin.UserClass
{
    public partial class List : System.Web.UI.Page
    {
        
        RoleService roleService = new RoleService();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Rp_Bind();
            }
        }

        /// <summary>
        /// repeater绑定事件
        /// </summary>
        protected void Rp_Bind()
        {
            RpList.DataSource = roleService.getAllRoles();
            RpList.DataBind();
        }

        /// <summary>
        /// repeater事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Rp_Event(object sender, RepeaterCommandEventArgs e)
        {
            string RoleId = ((HiddenField)e.Item.FindControl("role_id")).Value;
            BoRoles RoleModel = new BoRoles();
            RoleModel.ROL_ID = RoleId;
            switch (e.CommandName)
            { 
                case "del_user":
                    if (roleService.DeleteRole(RoleModel) == 0)
                        Response.Write("<script>alert('不允许删除系统用户')</script>");
                    break;
            }
            Rp_Bind();
            
        }
        
        ///// <summary>
        ///// 批量删除事件
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //protected void btnDelete_Click(object sender, EventArgs e) {
        //    int j = 0;
        //    for (int i = 0; i < RpList.Items.Count; i++)
        //    {
        //        int id = Convert.ToInt32(((Label)RpList.Items[i].FindControl("lb_id")).Text);
        //        CheckBox cb = (CheckBox)RpList.Items[i].FindControl("CbChoose");
        //        if (cb.Checked)
        //        {
        //            j += userclass.DeleteSingle(id);
        //        }
        //    }
        //    if (j > 0)
        //        Response.Write("<script>alert('删除成功，共删除" + j + "行数据');window.location.href='List.aspx'</script>");
        //    else
        //        Response.Write("<script>alert('删除失败');window.location.href='List.aspx'</script>");
        //}
    }
}